package cluster

import (
	"context"

	v1 "k8s.io/api/core/v1"
	meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (c *K8sClusterCache) listNodes() ([]v1.Node, error) {
	list, err := c.CoreV1().Nodes().List(context.Background(), meta_v1.ListOptions{})
	if err != nil {
		return nil, err
	}
	return list.Items, nil
}

func (c *K8sClusterCache) listPods() (map[string]*v1.Pod, error) {
	result := make(map[string]*v1.Pod)
	podList, err := c.CoreV1().Pods("").List(context.Background(), meta_v1.ListOptions{})
	if err != nil {
		return nil, err
	}
	for _, pod := range podList.Items {
		result[string(pod.UID)] = &pod
	}
	return result, nil
}
